package com.lb.web;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 功能描述: <br>
 * @Author: Edward
 * @Date: 2021/5/25 10:42
 */
@RestController
public class SendMessageController {

    @Resource
    private RabbitTemplate rabbitTemplate;
 
    @PostMapping("/sendDirectMessage")
    public String sendDirectMessage(@RequestBody Map requestParam) {
        //将消息携带绑定键值：TestDirectRouting 发送到交换机TestDirectExchange
        rabbitTemplate.convertAndSend("lb.direct", "LbDirectRouting", requestParam);
        return "ok";
    }

    @PostMapping("/sendTopicMessage1")
    public String sendTopicMessage1(@RequestBody Map requestParam) {
        rabbitTemplate.convertAndSend("lbTopicExchange", "topic.man", requestParam);
        return "ok";
    }

    @PostMapping("/sendTopicMessage2")
    public String sendTopicMessage2(@RequestBody Map requestParam) {
        rabbitTemplate.convertAndSend("lbTopicExchange", "topic.woman", requestParam);
        return "ok";
    }

    @PostMapping("/fanoutExchange")
    public String fanoutExchange(@RequestBody Map requestParam) {
        rabbitTemplate.convertAndSend("fanoutExchange", null, requestParam);
        return "ok";
    }
}